package com.tanjie.blackbean.system.admin.controller;

import cn.hutool.core.lang.tree.Tree;
import com.tanjie.blackbean.system.admin.model.menu.MenuDTO;
import com.tanjie.blackbean.system.admin.model.menu.MenuQuery;
import com.tanjie.blackbean.system.admin.model.menu.MenuVO;
import com.tanjie.blackbean.system.admin.service.IMenuService;
import com.tanjie.blackbean.web.annotation.BlackBeanController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 菜单管理
 *
 * @author tanjie
 * @since 2022-04-20
 */
@Tag(name = "菜单管理")
@BlackBeanController
@RequestMapping("menu")
public class MenuController {

    @Resource
    IMenuService menuService;

    @Operation(summary = "新增")
    @PostMapping("create")
    public void createMenuHandler(@RequestBody @Validated MenuDTO dto) {
        menuService.create(dto);
    }

    @Operation(summary = "更新")
    @PostMapping("update")
    public void updateMenuHandler(@RequestBody @Validated MenuDTO dto) {
        menuService.update(dto);
    }

    @Operation(summary = "删除")
    @GetMapping("delete")
    public void deleteMenuHandler(String id) {
        menuService.delete(id);
    }

    @Operation(summary = "获取详情")
    @GetMapping("detail")
    public MenuVO getMenuDetailHandler(String id) {
        return menuService.detail(id);
    }

    @Operation(summary = "列表查询")
    @PostMapping("list")
    public List<MenuVO> queryMenuListHandler(@RequestBody(required = false) MenuQuery dto) {
        return menuService.queryList(dto);
    }

    @Operation(summary = "树形数据查询")
    @PostMapping("tree")
    public List<Tree<String>> queryTreeHandler() {
        return menuService.tree();
    }

    @Operation(summary = "获取菜单路由表")
    @GetMapping("route")
    public List<Tree<String>> getRouteHandler() {
        return menuService.getRoute();
    }

    @Operation(summary = "获取角色已绑定的菜单")
    @GetMapping("roleBoundMenuList")
    public List<String> roleBoundMenuListHandler(@RequestParam("roleId") String roleId) {
        return menuService.roleBoundMenuList(roleId);
    }

}
